#ifndef INITMAP_H
#define INITMAP_H

#include <QObject>
#include <QThread>
#include <QImage>

#include <math.h>
#include <iostream>
using namespace std;

typedef struct{
    int ex,ey;
    int sr,sg,sb;
    int er,eg,eb;
}Point;


class InitMap : public QThread
{
    Q_OBJECT
public:
    explicit InitMap(QObject *parent = nullptr);

    ~InitMap();

    void init(QImage pic1, QImage pic2)
    {
        img1=pic1;
        img2=pic2;

        int i=0;
        map=(Point **)malloc(pic1.width()*sizeof(Point *));
        for(i=0;i<pic1.width();i++)
            map[i]=(Point *)malloc(pic1.height()*sizeof(Point));

        img2_tag=(bool **)malloc(pic2.width()*sizeof(bool *));
        for(i=0;i<pic1.width();i++)
            img2_tag[i]=(bool *)malloc(pic2.height()*sizeof(bool));
    }

    void calMap(Point &p);

    int colorDis(int dr,int db,int dg);

    void readMap();

    virtual void run(void) override;//多线程重载运行函数run
    
signals:
    void updateProgress();
    void complete();

public:
    double progress;
    QImage img1,img2;
    bool **img2_tag;
    Point **map;
};

#endif // INITMAP_H
